#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QtOpenGL/qgl.h>
#include <QGLWidget>
#include <QTimer>

#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLShaderProgram>

QT_BEGIN_NAMESPACE
class QPainter;
class QOpenGLContext;
class QOpenGLPaintDevice;
QT_END_NAMESPACE

class GLWidget : public QGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT
public:
    explicit GLWidget(QWidget *parent = 0);
    ~GLWidget();

protected:
    virtual void initialize();
    virtual void render();
    virtual void update();

    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);

    QVector2D PixelsToWorldPoint(int x, int y);
    QVector2D WorldToPixelsPoint(float x, float y);
    QVector2D PixelsToWorldLength(int dx);
    QVector2D WorldToPixelsLength(float dx);

    QTimer timer;
    QOpenGLShaderProgram *m_program;

protected slots:
    virtual void timeOutSlot();

};

#endif // GLWIDGET_H
